<!DOCTYPE html>
<html>
<head>
    <include file="Public:head"/>
    <title>角色部门数据权限</title>
    <style>
        body{
            font-size:12px;
        }
        .div-content{
            border-left:3px solid #d9534f;
            padding-left:10px;
            margin-bottom:20px;
            padding-top:0;
        }
        .div-content::after,.div-content::before{
            content: '!';
            border-radius: 15px;
            background-color:#d9534f;
            position: relative;

            left:-19px;
            height:15px;
            width:15px;
            display:inline-block;
            text-align: center;
            color:#fff;
        }
        .div-content::after{
            bottom:0;
        }
        .div-content::before{
            top:0;
        }
        .div-content p{
            padding-left:20px;
        }
        .lbl-item{
            font-weight:100;
            color:#333;
            font-size:12px;
        }
    </style>
</head>
<body>
<div class="container-fluid">
    <form class="form-inline">
        <div class="input-group">
            <div class="input-group-addon">角色</div>
            <select id="role" name="role" class="form-control">
                <volist name="roleList" id="vo">
                    <option value="{$vo.code}">{$vo.name}</option>
                </volist>
            </select>
        </div>
        <div class="input-group">
            <div class="input-group-addon">菜单类别</div>
            <select id="category" name="category" class="form-control">
                <volist name="menuCategoryList" id="vo">
                    <option value="{$vo.code}">{$vo.name}</option>
                </volist>
            </select>
        </div>
        <button class="btn btn-default"><i class="fa fa-search"></i>&nbsp;搜索</button>
    </form>
    <div class="div-content">
        <h3>{$menuCategoryName}</h3>
        <volist name="menuList" key="k" id="menu">
            <php>
                $type = '';
                foreach($roleMenuOrgList as $roleMenuOrg){
                    if($roleMenuOrg['menu_code'] == $menu['code']){
                        $type = $roleMenuOrg['type'];
                    }
                }
            </php>
            <p class="p-menu {$menu.code}" menuCode = "{$menu.code}">
                <label>{$menu.name}</label>
                &#12288;&#12288;
                <volist name="typeList" key="typeK" id="type">
                    <php>
                        $checked = '';
                        foreach($roleMenuOrgList as $roleMenuOrg){
                            if($roleMenuOrg['menu_code'] == $menu['code'] && $roleMenuOrg['type'] == $type['code']){
                                $checked = 'checked';
                            }
                        }
                    </php>
                    <input type="radio" {$checked} menuCode="{$menu.code}"  name="type{$k}" id="type{$k}{$typeK}" class="type" value="{$type.code}"/>
                    <label class="lbl-item" for="type{$k}{$typeK}">{$type.title}</label>&nbsp;
                </volist>
                <if condition="$type eq 6"></if>
            </p>
        </volist>
    </div>

    <div class="btnClear" style="clear: both;"></div><br/>
    <button id="btn-sure" class="btn btn-info">保存</button>
</div>
</body>
</html>
<script>
    $("#category").val("{$category_code|default=''}");
    $("#role").val("{$role_code|default=''}");

    $(function(){
        $(".p-menu").each(function(){
            var checkLen = $(this).find(".column:checked").length;
            var allLen = $(this).find(".column").length;
            if(allLen >0 && checkLen == allLen){
                $(this).find(".checkAll").prop('checked', true);
            }
        });
    });

    $("#btn-sure").click(function(){
        var param = new Object();
        param.role_code = $("#role").val();
        param.menu_type = new Array();
        param.menu_codes = new Array();
        $(".p-menu").each(function(){
            var menuCode = $(this).attr("menuCode");
            param.menu_codes.push(menuCode);
        });

        $(".type:checked").each(function(){
            var paramTemp = new Object();
            paramTemp.menu_code = $(this).attr("menuCode");
            paramTemp.type = $(this).val();
            param.menu_type.push(paramTemp);
        });

        $.ajax({
            url:"__URL__/ajax_save",
            type:"post",
            dataType:"json",
            data:param,
            success:function(data){
                alert(data.msg);
            }
        });
    });
</script>